package com.zpb.portal.controller;

import com.zpb.framework.domain.ApiResult;
import com.zpb.framework.domain.entity.Article;
import com.zpb.framework.domain.entity.ArticleDetailVo;
import com.zpb.framework.domain.vo.HotArticleVo;
import com.zpb.framework.domain.vo.PageVo;
import com.zpb.framework.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:
 * @Author: zhaopengbo
 * @Date: 2025/9/7
 */
@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;
//    @GetMapping("/list")
//    public List<Article> test(){
//        return articleService.list();
//    }
    @GetMapping("/hotArticleList")
    public ApiResult<List<HotArticleVo>> hotArticleList(){
        return articleService.getHotArticleList();
    }

    @GetMapping("/articleList")
    public ApiResult<PageVo> getListByCondition(@RequestParam(defaultValue = "1") Integer pageNum,
                                                @RequestParam(defaultValue = "10") Integer pageSize,
                                                Article article){
        return articleService.getListByCondition(pageNum,pageSize,article);

    }

    @GetMapping("/{id}")
    public ApiResult<ArticleDetailVo> getDetailById(@PathVariable("id") Long id){
        return articleService.getDetailById(id);
    }
    @PutMapping("/updateViewCount/{aId}")
    public ApiResult updateViewCount(@PathVariable("aId") Long articleId){
        return articleService.addViewCount(articleId);
    }
}
